#include <bits/stdc++.h>
using namespace std;
int m[11][11];
int dist[11][11] = {0};
int ans = INT_MIN;
// 上右下左
int dr[4] = {-1, 0, 1, 0}, dc[4] = {0, 1, 0, -1};
int R, C;
void dfs(int r, int c, int dis)
{
    //cout << r << " --- " << c << endl;
    dist[r][c] = dis;
    ans = max(ans, dis);
    for(int i = 0; i < 4; ++i)
    {
        int nr = r + dr[i], nc = c + dc[i];
        if(nr < 0 || nr >= R || nc < 0 || nc >= C) continue;
        // 下一个定点必须必当前顶点更高, 并且下一个顶点多次进入的情况下, 必须长度更长才能进行dfs
        if(dist[nr][nc] >= dis + 1 || m[nr][nc] <= m[r][c]) continue;
        dfs(nr, nc, dis + 1);
    }
}
int main()
{
#ifdef LOCAL
    freopen("ADV-294.in", "r", stdin);
#endif
    cin >> R >> C;
    for(int i = 0; i < R; ++i)
        for(int j = 0; j < C; ++j)
            cin >> m[i][j];
    for(int i = 0; i < R; ++i)
        for(int j = 0; j < C; ++j)
            if(dist[i][j] == 0) dfs(i, j, 1);
    cout << ans << endl;
    return 0;
}